package com.github.nuggets.controller;

import com.github.nuggets.model.pojo.LoginAccountInfo;
import com.github.nuggets.model.result.BaseResult;
import com.github.nuggets.model.result.PageResult;
import com.github.nuggets.model.vo.NuggetsAccountDetailVO;
import com.github.nuggets.service.AccountRelationshipService;
import com.github.nuggets.util.LoginAccountUtils;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 登录用户的用户关系相关接口
 * @author: wangsj
 * @date: 2022/3/18 2:40 下午
 */
@RestController
@RequestMapping("/nuggets")
public class LoginAccountRelationshipController {


    @Autowired
    private AccountRelationshipService accountRelationshipService;

    @Operation(summary = "关注用户", description = "关注用户")
    @PostMapping("/fouc/{accountId}")
    public BaseResult<Boolean> foucAccount(OAuth2Authentication auth, @PathVariable Long accountId) {
        LoginAccountInfo loginAccount = LoginAccountUtils.getLoginAccount(auth);
        return BaseResult.success(accountRelationshipService.foucAccount(loginAccount.getId(), accountId));
    }

    @Operation(summary = "取关用户", description = "取关用户")
    @DeleteMapping("/fouc/{accountId}")
    public BaseResult<Boolean> cancelFoucAccount(OAuth2Authentication auth, @PathVariable Long accountId) {
        LoginAccountInfo loginAccount = LoginAccountUtils.getLoginAccount(auth);
        return BaseResult.success(accountRelationshipService.cancelFoucAccount(loginAccount.getId(), accountId));
    }


    @Operation(summary = "关注列表", description = "用户关注列表")
    @GetMapping("/fouc")
    public BaseResult<PageResult<NuggetsAccountDetailVO>> foucList(OAuth2Authentication auth,
                                                             @RequestParam("pageIndex") Integer pageIndex,
                                                             @RequestParam("pageSize") Integer pageSize){
        LoginAccountInfo loginAccount = LoginAccountUtils.getLoginAccount(auth);
        return BaseResult.success(accountRelationshipService.foucList(loginAccount.getId(),pageIndex,pageSize));
    }


    @Operation(summary = "粉丝列表", description = "用户粉丝列表")
    @GetMapping("/fans")
    public BaseResult<PageResult<NuggetsAccountDetailVO>> fansList(OAuth2Authentication auth,
                                                                   @RequestParam("pageIndex") Integer pageIndex,
                                                                   @RequestParam("pageSize") Integer pageSize){
        LoginAccountInfo loginAccount = LoginAccountUtils.getLoginAccount(auth);
        return BaseResult.success(accountRelationshipService.fansList(loginAccount.getId(),pageIndex,pageSize));
    }



}
